<?php
/**
 * @Author: anchen
 * @Date:   2016-05-05 11:31:17
 * @Last Modified by:   anchen
 * @Last Modified time: 2016-09-07 18:30:25
 */
header("Content-type:text/html;charset=utf-8");
//--->>>test(1)
//$a=0=='c';//结果为true
//分析:1.$a赋值0,是数字类型;2.$a和字符串c进行比较,因为是和数字比较,所以字符串会转换成数字,若字符串转换失败返回0,转换成功返回对应数字;3.转换后的字符串第一个不是数字返回0,与$a比较相等,所以结果为true;(如果字符串第一个是数字则返回对应数字,再与0比较,相等则为true,不相等则为false)
//var_dump($a=0=='c');



//--->>>test(2)
//自定义一个类
/*class test{
    public function Test($n){
        for($i=0;$i<count($n[$i]);$i++){
            for($j=0;$j<count($n[$i]);$j++){
                echo $n[$i][$j]."=".$n[$j][$i];
                echo "&nbsp;";
            }
            echo "<br/>";
        }
    }
}

$b=array(array(1,2,3),array(4,5,6),array(7,8,9));
$c=new test();
$c->Test($b);*/



//--->>>test(3)
//百分数也可以做比较
/*$a = '0.3427%';
$b = '2.5165%';
$map = $a<$b;
var_dump($map);*/



//--->>>test(4)
/*$str = '\012';
var_dump($str);*/



//--->>>test(5)
/*$array=array(array(1,2,3),array(4,5,6),array(7,8,9));
foreach($array as $array){
    echo '<pre>';
    print_r($array);
    echo '</pre>';
}*/



//--->>>test(6)
//include用法
/*$a = 2008;
$b = 2;
$c = include('include.php');
echo "以上程序的执行结果是:<br>";
echo "两年以后是{$c}年";*/



//--->>>test(7)
/*$one = 20;//单次
$ten = 400;//一键全部
$total = 62180;//总数
$num = 2321;//统计的总次数
//求$a的次数,$b的次数
$m = $n = 0;
for($n=0;$n<$total/$one;$n++){
    for($m=0;$m<$total/$ten;$m++){
        if($one*$n+$ten*$m==62180){
            if(($n+$m)==$num){
                echo '<div style="border:1px solid red;text-align:center;width:150px;margin:20px 30px;padding:10px;">';
                echo '单次次数=',$n,'<br/>一键全部次数=',$m;
                echo '</div>';
            }
        }
    }
}*/



//--->>>test(8)
/*$a = array(
    "get" => array(
                0 => array("zhenqi" => "获得真气:2000, "),
                1 => array("获得经验:5070, "),
                2 => array("money" => "获得铜钱:20000, "),
                4 => array("获得物品:新手礼包(1个), ")
            ),
    "consum" => array(
                3 => "减少物品:高级青铜剑(1个), "
            )
    );
foreach($a['get'] as $k=>$v){
    if(!empty($v['money'])){
        var_dump($v['money']);
    }
    echo '<br/>----------------------';
}*/

/*$a = array(
    "get" => array(
                0 => array("zhenqi" => "获得真气:2000, "),
                1 => "获得经验:5070, ",
                2 => array("money" => "获得铜钱:20000, "),
                4 => "获得物品:新手礼包(1个), "
            ),
    "consum" => array(
                3 => "减少物品:高级青铜剑(1个), "
            )
    );
foreach($a['get'] as $k=>$v){
    var_dump(empty($v['money']));
}*/



//--->>>test(9)
//$a = 5;
//echo date("Y-m-d",strtotime("-".$a." day"));//前n天的日期



//--->>>test(10)
/*$a =1 ;
$b = &$a;//这里不注释$c结果为5,注释则$c结果为4
$c = ++$a+$a++;*/
// 结果$c是多少？
//echo "<br/>$c";



//--->>>test(11)
/*$val=9.45;//计算机中实际存储为:9.44999999999999999...
$result=$val*100;//实际为:944.999999999999...
echo $result%100;*/  //所以结果为:44



//--->>>test(12)
//递归函数例子一:引用地址
/*function test($a=0,&$result=array()){
    $a++;
    if ($a<10) {
        $result[]=$a;
        test($a,$result);
    }
    echo $a,'<br>';
    return $result;
}
test();*/



//--->>>test(13)
//递归函数例子二:静态变量
/*function test($a=0){
    static $result=array();
    $a++;
    if ($a<10) {
        $result[]=$a;
        test($a);
    }
    echo $a,'<br>';
    return $result;
}
test();*/



//--->>>test(14)
//数组合并,其中一个可以是空数组,但要保证是数组,否则报错
/*$a1=array('cc'=>array("a"=>"red","b"=>"green"));
$a2=array();
echo '<pre>';
var_dump($a2);
print_r(array_merge($a1,$a2));
echo '</pre>';*/



//--->>>test(15)
//天气预报接口(有两个可用网址)
/*$city_code = "101280601";//'深圳'=101280601;
$json1 = file_get_contents("http://www.weather.com.cn/data/sk/".$city_code.".html");
$json2 = file_get_contents("http://www.weather.com.cn/data/cityinfo/".$city_code.".html");
$data1 = json_decode($json1);
$data2 = json_decode($json2);
//输出内容
echo "<br>sk网址JSON内容:<br>城市:".$data1->weatherinfo->city."<br>cityid:".$data1->weatherinfo->cityid."<br>温度(temp):".$data1->weatherinfo->temp."<br>风向(WD):".$data1->weatherinfo->WD."<br>风速(WS):".$data1->weatherinfo->WS."<br>相对湿度(SD):".$data1->weatherinfo->SD."<br>风力(WSE):".$data1->weatherinfo->WSE."<br>更新时间(time):".$data1->weatherinfo->time."<br>njd:".$data1->weatherinfo->njd;
echo "<br><br>--------------------<br>";
echo "<br>cityinfo网址JSON内容:<br>城市:".$data2->weatherinfo->city."<br>cityid:".$data2->weatherinfo->cityid."<br>温度1(temp1):".$data2->weatherinfo->temp1."<br>温度2(temp2):".$data2->weatherinfo->temp2."<br>天气(weather):".$data2->weatherinfo->weather."<br>img1:".$data2->weatherinfo->img1."<br>img2:".$data2->weatherinfo->img2."<br>更新时间(ptime):".$data2->weatherinfo->ptime;*/



//--->>>test(16)
//天气接口(百度)
/*$ch = curl_init();
$url = 'http://apis.baidu.com/apistore/weatherservice/citylist?cityname=%E6%9C%9D%E9%98%B3';
$header = array(
    'apikey: 8VgDAZW9Rr3mXcnjjS7zBdE7jGryjUnY',
);
// 添加apikey到header
curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 执行HTTP请求
curl_setopt($ch , CURLOPT_URL , $url);
$res = curl_exec($ch);
var_dump(json_decode($res));*/



//--->>>test(17)
//以 CReq 或者 CRsp 或者 CRequest 或者 CResponse 开头,以字母结尾的正则表达式
/*echo "<html>
<head>
<meta charset='utf-8'>
</head>
<body>
以 CReq 或者 CRsp 或者 CRequest 或者 CResponse 开头,以字母结尾的正则表达式
<br><br>
<form action='test.php' method='get'>
<input type='text' value='' name='word'><br>
<input type='submit' value='提交'>
</form>
</body>
</html>";
$word = empty($_GET['word'])?'':$_GET['word'];
echo '<br/>word='.$word;
preg_match('/^(CReq|CRequest|CRsp|CResponse)\w*[a-zA-Z]$/',$word,$res);
var_dump($res);*/



//--->>>test(18)
//微信公众号自定义菜单接口
/*function getAccessToken(){
    $APPID = "wx813c72a2606de89e";
    $APPSECRET = "f79df7b5b08c4c2717ac3e903f2a5bcf";
    $TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;

    $json = file_get_contents($TOKEN_URL);
    $result = json_decode($json,true);
    print_r($result);

}
getAccessToken();*/



//--->>>test(19)
//curl函数封装一
/*function curl_http_request($url,$timeout=30,$header=array()){
    if (!function_exists('curl_init')) {
        throw new Exception('server not install curl');
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    if (!emptyempty($header)) {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    }
    $data = curl_exec($ch);
    list($header, $data) = explode("\r\n\r\n", $data);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code == 301 || $http_code == 302) {
        $matches = array();
        preg_match('/Location:(.*?)\n/', $header, $matches);
        $url = trim(array_pop($matches));
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        $data = curl_exec($ch);
    }
    if ($data == false) {
        curl_close($ch);
    }
    @curl_close($ch);
    return $data;
}*/



//--->>>test(20)
//微信公众号自定义菜单接口
//curl函数封装二 (curl代替file_get_contents请求http,https)
/*function curl_http_request(){
    $APPID = "wx813c72a2606de89e";
    $APPSECRET = "f79df7b5b08c4c2717ac3e903f2a5bcf";
    $TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $TOKEN_URL);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    // https请求 不验证证书和hosts
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

    $data = curl_exec($curl);

    curl_close($curl);

    print_r($data);
}
curl_http_request();*/



//--->>>test(21)
//微信测距接口
/*$locationY = "113.850845";//经度
$locationX = "22.605574";//纬度
$url = "http://api.map.baidu.com/telematics/v2/distance?waypoints=113.858783,22.612221;".$locationY.",".$locationX."&output=json&ak=GaGHpmGlhnKymLa4xy4ZurU8ujKIL0CO";
$file_c = file_get_contents($url);
$file_json = json_decode($file_c);
$dist = $file_json->results[0];
echo '<pre>file_json=<br>';
print_r($file_json);
echo '<br>dist=',$dist;
if($dist>3000){
    $dist = round($dist/1000,3)."公里";
}else{
    $dist = round($dist,1)."米";
}
echo "<br>你和我的距离有".$dist."远";
echo '</pre>';*/



//--->>>test(22)
//形参,实参; 如要使用形参可以不给值,但只限实参后面的形参,实参中间留空报错,给空值会变实参空值
/*function angelababy($a='a',$n='n',$g='g',$e='e',$l='l'){
    $result = array(
        'a' => $a,
        'n' => $n,
        'g' => $g,
        'e' => $e,
        'l' => $l
        );
    $str = "angel<br>".$a.$n.$g.$e.$l;
    return $str;
}
$res = angelababy('a','p');
echo '<br>';
print_r($res);*/



//--->>>test(23)
/*$array = array(
    array('A','n','g','e','l','a'),//注释一
    array('b','a','b','y'),//注释二
    array('I','love','you')//注释三(这里的注释不会报错)
    );
$str = "";
foreach($array as $ak=>$av){
    if($ak==2){
        foreach($av as $vs){
            $str .= $vs."&nbsp;";
        }
        $str .= "!";
    }else{
        foreach($av as $vb){
            $str .= $vb;
        }
        if($ak==1){
            $str .= ",";
        }
    }
}
print_r($str);*/



//--->>>test(24)
//数组转换成json格式
//注释说明:F表示一级菜单,S表示二级菜单,后面数字表示是第几个;
/*$menuArr = array(
    "button" => array(
        array(
            "type" => "click",
            "name" => "今日歌曲",
            "key"  => "M001"
        ),//F1
        array(
            "name"       => "有种你点",
            "sub_button" => array(
                array(
                    "type" => "view",
                    "name" => "搜索",
                    "url"  => "http://www.baidu.com/"
                ),//F2-S1
                array(
                    "type" => "view",
                    "name" => "视频",
                    "url"  => "http://m.v.qq.com/"
                ),//F2-S2
                array(
                    "type" => "click",
                    "name" => "赞一下我们",
                    "key"  => "likes"
                )//F2-S3
            )
        ),//F2
        array(
            "name" => "服务功能",
            "sub_button"  => array(
                array(
                    "type" => "scancode_waitmsg",
                    "name" => "扫码",
                    "key"  => "scancode",
                    "sub_button" => array()
                ),//F3-S1
                array(
                    "type" => "pic_sysphoto",
                    "name" => "系统拍照发图",
                    "key"  => "photo",
                    "sub_button" => array()
                )//F3-S2
            )
        )//F3
    )
);
//将数组转换为json格式
$menuArr = json_encode($menuArr);
echo '<pre>menuArr=<br>';
print_r($menuArr);
echo '</pre>';*/



//--->>>test(25)








?>
<!-- <html>
    <head>
        <meta charset="utf-8">
        <script src="jquery-1.8.3.js" type="text/javascript" ></script>
        <script>
        $(function() {
            $('li a').click(function(){
                $('li').find('a').removeClass('active');
                $(this).addClass('active');
            })
        });
        </script>
        <style>
        body,ul,li{margin:0;padding:0;}
        body{margin:50px auto;width:1000px;height:500px;}
        ul{list-style: none;}
        li{margin-right:10px;border:1px solid blue;width:50px;height:50px;}
        li,a{display: block;float:left;}
        a{width:46px;height:46px;}
        .active{border:2px solid red;}
        </style>
    </head>
    <body>
        <ul>
            <li><a href="#" >1</a></li>
            <li><a href="#" >2</a></li>
            <li><a href="#" >3</a></li>
            <li><a href="#" >4</a></li>
            <li><a href="#" >5</a></li>
        </ul>
    </body>
</html> -->
